﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LibraryManagementSystem.master
{
    class masterSql
    {
        static string connectionStr = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=masterTable;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
        SqlConnection con = new SqlConnection(connectionStr);
        





        public void judgeDB()
        {
            try
            {//检测数据库是否连接正确
                con.Open();//打开数据库
            }
            catch
            {
                MessageBox.Show("数据库连接错误", "错误提示");
            }
            finally
            {
                con.Close();//关闭数据库
            }
        }





        //对管理员数据库的增删改查：
        //检索master
        bool searchMaster(int masterId)
        {
            //string searchStr = "select m from "


            return false;
        }



        //addMaster   
        public void addMaster(int masterId, String masterName)
        {
            judgeDB();//先检测数据库连接性
            string insert = "insert into userTable values(" + masterId + "," + masterName+ ")";
            SqlCommand mycom = new SqlCommand(insert, con);
            con.Open();
            mycom.ExecuteNonQuery();
            con.Close();
        }

        //deleteMaster
        public void deleteMaster(int masterId)
        {
            judgeDB();






        }

    }
}
